/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.transfer.service.impl;

import me.zhengjie.modules.transfer.domain.TransferIc66;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.modules.transfer.service.TransferIc66Service;
import me.zhengjie.modules.transfer.domain.dto.TransferIc66QueryCriteria;
import me.zhengjie.modules.transfer.mapper.TransferIc66Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author lzw
* @date 2025-05-28
**/
@Service
@RequiredArgsConstructor
public class TransferIc66ServiceImpl extends ServiceImpl<TransferIc66Mapper, TransferIc66> implements TransferIc66Service {

    private final TransferIc66Mapper transferIc66Mapper;

    @Override
    public PageResult<TransferIc66> queryAll(TransferIc66QueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(transferIc66Mapper.findAll(criteria, page));
    }

    @Override
    public List<TransferIc66> queryAll(TransferIc66QueryCriteria criteria){
        return transferIc66Mapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TransferIc66 resources) {
        transferIc66Mapper.insert(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TransferIc66 resources) {
        TransferIc66 transferIc66 = getById(resources.getAaz701());
        transferIc66.copy(resources);
        transferIc66Mapper.updateById(transferIc66);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<String> ids) {
        transferIc66Mapper.deleteBatchIds(ids);
    }

    @Override
    public void download(List<TransferIc66> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TransferIc66 transferIc66 : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("系统跟踪流水号", transferIc66.getAaz341());
            map.put("转出地行政区划代码", transferIc66.getAab301());
            map.put("转入地行政区划代码", transferIc66.getAab299());
            map.put("联系函编号", transferIc66.getAae270());
            map.put("信息表编号", transferIc66.getAae405());
            map.put("转出险种类型", transferIc66.getAae140());
            map.put("转入险种类型", transferIc66.getAae241());
            map.put("转出地人员编号", transferIc66.getAac319());
            map.put("人员编号", transferIc66.getAac001());
            map.put("社会保障号码", transferIc66.getAac002());
            map.put("姓名", transferIc66.getAac003());
            map.put("性别", transferIc66.getAac004());
            map.put("出生日期", transferIc66.getAac006());
            map.put("户口所在地址", transferIc66.getAac010());
            map.put("转移账户类别", transferIc66.getAae473());
            map.put("农民工标识", transferIc66.getAac028());
            map.put("转移日期", transferIc66.getAae035());
            map.put("关系转移制度方向", transferIc66.getAic113());
            map.put("转移类型", transferIc66.getAae173());
            map.put("转出单位名称", transferIc66.getAab004());
            map.put("参加工作日期", transferIc66.getAac007());
            map.put("首次参保地实行个人缴费时间", transferIc66.getAab305());
            map.put("首次参保年月", transferIc66.getAac049());
            map.put("本人建立个人账户日期", transferIc66.getAac032());
            map.put("在本地缴费起始时间", transferIc66.getAae030());
            map.put("在本地缴费终止时间", transferIc66.getAae031());
            map.put("在本地实际缴费月数", transferIc66.getAae201());
            map.put("1998年1月1日至调转上年末个人账户累计储存额", transferIc66.getAic089());
            map.put("1998年1月1日前账户中个人缴费累计储存额", transferIc66.getAic093());
            map.put("调转当年记入个人账户本金金额", transferIc66.getAic082());
            map.put("个人账户基金转移额", transferIc66.getAic083());
            map.put("统筹基金转移额", transferIc66.getAic084());
            map.put("转移基金总额", transferIc66.getAic102());
            map.put("基金划转银行票据号", transferIc66.getAad019());
            map.put("转入地社保机构名称", transferIc66.getAaa146());
            map.put("转出地社保机构名称", transferIc66.getAab300());
            map.put("人员转移流水号", transferIc66.getAae062());
            map.put("被确认标志", transferIc66.getAae733());
            map.put("上传标志", transferIc66.getAae730());
            map.put("上传方经办人", transferIc66.getAae736());
            map.put("上传方经办时间", transferIc66.getAae739());
            map.put("手机号码", transferIc66.getAac067());
            map.put("转移数据来源", transferIc66.getAac306());
            map.put("人员参保关系ID", transferIc66.getAaz159());
            map.put("联网下载标志", transferIc66.getAae732());
            map.put("备注", transferIc66.getAae013());
            map.put("经办人", transferIc66.getAae011());
            map.put("经办时间", transferIc66.getAae036());
            map.put("经办机构", transferIc66.getAab359());
            map.put("业务日志ID", transferIc66.getAaz002());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
